package bb.lanxing.lib.devices.antplus;

import java.util.LinkedHashSet;
import java.util.Set;
import android.util.Log;


public class AntPlusDataDispatcher {
    private static AntPlusDataDispatcher INSTANCE;
    private final Set<Object> mListenerSet = new LinkedHashSet();

    public interface OnAntPlusCandenceListener {
        void onCadenceData(int i, int i2, int i3);

        void onCadenceData(int i, int i2, int i3, int i4, int i5, int i6, int i7);
    }

    public interface OnAntPlusHeartrateListener {
        void onHeartrate(int i, int i2);
    }

    public interface OnAntPlusPowerrateListener {
        void onPowerrate(int i, int i2);
    }
    public interface OnAntPlusBiketrainerListener {
        void onBiketrainer(int i, int i2, int i3, int i4);
    }
    public interface OnAntPlusIndoorbikeListener {
        void onIndoorbike(int i, double i2, int i3, int i4, int i5, int i6, double i7, int i8);
    }

    public interface OnAntPlusCrosstrainerListener {
        void onCrosstrainer(int i, double i2, double i3, int i4, int i5, int i6, int i7 , int i8);
    }

    public interface OnAntPlusRowerListener {
        void onRower(int i, int i2, int i3, int i4, double i5, double i6, int i7 , int i8,int i9);
    }

    public static AntPlusDataDispatcher getInstance() {
        synchronized (AntPlusDataDispatcher.class) {
            if (INSTANCE == null) {
                INSTANCE = new AntPlusDataDispatcher();
            }
        }
        return INSTANCE;
    }

    private AntPlusDataDispatcher() {
    }


    synchronized void notifyHeartrateData(int i) {
        for (Object obj : this.mListenerSet) {
            if (obj instanceof OnAntPlusHeartrateListener) {
                ((OnAntPlusHeartrateListener) obj).onHeartrate(3, i);
            }
        }
    }

    public synchronized void notifyPowerrateData(int i) {
        for (Object obj : this.mListenerSet) {
            if (obj instanceof OnAntPlusPowerrateListener) {
                ((OnAntPlusPowerrateListener) obj).onPowerrate(3, i);
            }
        }
    }

    public synchronized void notifyBiketrainerData(int i1, int i2, int i3) {
        for (Object obj : this.mListenerSet) {
            if (obj instanceof OnAntPlusBiketrainerListener) {
                ((OnAntPlusBiketrainerListener) obj).onBiketrainer(3, i1,i2,i3);
            }
        }
    }

    public synchronized void notifyIndoorbikeData(int i,int i2, int i3, int i4, int i5, double i6,int i7) {
        for (Object obj : this.mListenerSet) {
            if (obj instanceof OnAntPlusIndoorbikeListener) {
                ((OnAntPlusIndoorbikeListener) obj).onIndoorbike(3, i, i2, i3, i4, i5, i6,i7);
            }
        }
    }

    public synchronized void notifyCrosstrainerData(int i,int i2, int i3, int i4, int i5, int i6 , int i7) {
        for (Object obj : this.mListenerSet) {
            if (obj instanceof OnAntPlusCrosstrainerListener) {
                ((OnAntPlusCrosstrainerListener) obj).onCrosstrainer(3, i, i2, i3, i4, i5, i6,i7);
            }
        }
    }

    public synchronized void notifyRowerData(int i,int i2, int i3, int i4, int i5, int i6 , int i7, int i8) {
        for (Object obj : this.mListenerSet) {
            if (obj instanceof OnAntPlusRowerListener) {
                ((OnAntPlusRowerListener) obj).onRower(3, i, i2, i3, i4, i5, i6,i7,i8);
            }
        }
    }


    public synchronized void notifyCadenceData(int i, int i2) {
        for (Object obj : this.mListenerSet) {
            if (obj instanceof OnAntPlusCandenceListener) {
                ((OnAntPlusCandenceListener) obj).onCadenceData(2, i, i2);
            }
        }
    }

    synchronized void notifyRawCadenceData(int i, int i2, int i3, int i4, int i5, int i6) {
        for (Object obj : this.mListenerSet) {
            if (obj instanceof OnAntPlusCandenceListener) {
                ((OnAntPlusCandenceListener) obj).onCadenceData(2, i, i2, i3, i4, i5, i6);
            }
        }
    }

    public synchronized void registerAntPlusDataListener(Object obj) {
        if (obj != null) {
            this.mListenerSet.add(obj);
        }
    }

    public synchronized void ungisterAntPlusDataListener(Object obj) {
        if (obj != null) {
            this.mListenerSet.remove(obj);
        }
    }

    public static void terminate() {
        synchronized (AntPlusDataDispatcher.class) {
            AntPlusDataDispatcher antPlusDataDispatcher = INSTANCE;
            if (antPlusDataDispatcher != null) {
                antPlusDataDispatcher.mListenerSet.clear();
                INSTANCE = null;
            }
        }
    }
}
